package com.bloveoa.zkkd.util;

import com.bloveoa.zkkd.exception.CommonException;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.function.Supplier;

@Data
@ApiModel(value="R",description="统一数据信息")
public class R<T> implements Serializable{
    @ApiModelProperty(value="状态吗",name="code",example="0")
    public int code;
    @ApiModelProperty(value="错误信息",name="msg",example="密码不对")
    public String msg;
    @ApiModelProperty(value="对象信息",name="data",example="")
    public T data;

    public static Supplier<CommonException> exception(Enum em) {
        return () -> new CommonException(em);
    }
    /**
     * 正数需要进行进一步操作
     * 0 正常业务操作流程
     * 负数出现错误
     */
    public enum Enum {

        /**
         * 金额不足
         */
        INPUT_DATA_ERROR(-100, "传入的数据不合法"),
        TX_HASH_EXISTS(-103, "该交易hash已经存在"),
        ADDRESS_ERROR(-102, "地址不合法"),
        MAC_ERROR(-103, "mac不合法"),
        USER_NOT_FOUND(-104, "当前用户不存在"),
        USER_BIINDED(-105, "钱包已绑定盒子"),
        LOCKED_ERROR(-106, "锁仓失败"),
        ;


        @Getter
        @Setter
        private int code;

        @Getter
        @Setter
        private String message;

        Enum(int code, String message) {
            this.code = code;
            this.message = message;
        }


    }

}
